import { useSize } from 'ahooks';

interface ScreenSizeReturn {
  width?: number;
  height?: number;
  isMobile?: boolean;
}

const useScreenSize = (): ScreenSizeReturn => {
  const size = useSize(document.body);
  return {
    width: size?.width,
    height: size?.height,
    isMobile: size?.width ? size.width < 640 : undefined,
  };
};

export default useScreenSize;

// 判断当前是否为移动端 (钩子外)
export const isMobile = () => {
  return document.body.clientWidth < 640;
};
